<?php


namespace app\admin\controller;

use app\admin\model\Password as PasswordModel;
use think\response\Json;

class Password extends ApiCommon
{
    /**
     * 用于判断权限
     * @permission 无限制
     * @allow 登录员工可访问
     * @other 其他根据系统设置
     **/
    public function initialize()
    {
        $action = [
            'permission' => [],
            'allow' => [
            ]
        ];
        // Hook::listen('check_auth',$action);
        event('CheckAuth',$action);
        // event(new \app\event\CheckAuth($action));

        $request = $this->request;
        $a = strtolower($request->action());
        if (!in_array($a, $action['permission'])) {
            parent::initialize();
        }
    }

    /**
     * 密码策略
     * @return \think\response\Json
     * @author Mr.Li
     * @create 2021-07-29 15:51
     */
    public function rule(PasswordModel $passwordModel): Json
    {
        $method    = request()->method();
        $data = [];
        if($method == 'GET'){
            $data = $passwordModel->getDataList();
        }else if($method == 'PUT'){
            $param = $this->param;
            $data = $passwordModel->saveData($param);
            if (!$data) {
                return resultArray(['error' => $passwordModel->getError()]);
            }
            return resultArray(['data' => [],'error'  => '保存成功']);
        }

        return resultArray(['data' => $data]);
    }


}
